// 更新状态栏时间
function updateStatusBarTime() {
    const now = new Date();
    let hours = now.getHours();
    let minutes = now.getMinutes();
    
    // 格式化时间为两位数
    hours = hours < 10 ? '0' + hours : hours;
    minutes = minutes < 10 ? '0' + minutes : minutes;
    
    const timeString = `${hours}:${minutes}`;
    
    // 更新所有状态栏时间元素
    const timeElements = document.querySelectorAll('.status-bar-time');
    timeElements.forEach(el => {
        el.textContent = timeString;
    });
}

// 初始化页面
document.addEventListener('DOMContentLoaded', function() {
    // 设置初始时间
    updateStatusBarTime();
    
    // 每分钟更新一次时间
    setInterval(updateStatusBarTime, 60000);
    
    // 处理底部导航栏点击
    const tabItems = document.querySelectorAll('.tab-item');
    tabItems.forEach(item => {
        item.addEventListener('click', function() {
            // 移除所有active类
            tabItems.forEach(tab => tab.classList.remove('active'));
            // 添加active类到当前点击的项
            this.classList.add('active');
            
            // 添加点击动画
            this.classList.add('pulse');
            setTimeout(() => {
                this.classList.remove('pulse');
            }, 300);
        });
    });
    
    // 处理点赞按钮
    const likeButtons = document.querySelectorAll('.like-button');
    likeButtons.forEach(button => {
        button.addEventListener('click', function() {
            const icon = this.querySelector('i');
            if (icon.classList.contains('far')) {
                // 未点赞状态 -> 已点赞
                icon.classList.remove('far');
                icon.classList.add('fas');
                icon.style.color = '#ff2d55';
                
                // 更新点赞数
                const countEl = this.querySelector('span');
                if (countEl) {
                    let count = parseInt(countEl.textContent);
                    countEl.textContent = (count + 1).toString();
                }
            } else {
                // 已点赞状态 -> 未点赞
                icon.classList.remove('fas');
                icon.classList.add('far');
                icon.style.color = '';
                
                // 更新点赞数
                const countEl = this.querySelector('span');
                if (countEl) {
                    let count = parseInt(countEl.textContent);
                    countEl.textContent = (count - 1).toString();
                }
            }
        });
    });
    
    // 处理关注按钮
    const followButtons = document.querySelectorAll('.follow-button');
    followButtons.forEach(button => {
        button.addEventListener('click', function() {
            if (this.textContent.trim() === '关注') {
                this.textContent = '已关注';
                this.classList.remove('primary-button');
                this.classList.add('secondary-button');
            } else {
                this.textContent = '关注';
                this.classList.remove('secondary-button');
                this.classList.add('primary-button');
            }
        });
    });
    
    // 处理标签点击
    const tags = document.querySelectorAll('.tag');
    tags.forEach(tag => {
        tag.addEventListener('click', function() {
            this.classList.toggle('active');
        });
    });
});

// 模拟视频播放功能
function playVideo(videoElement) {
    const playIcon = videoElement.querySelector('.video-play-icon');
    if (playIcon) {
        playIcon.style.display = 'none';
    }
    
    // 这里只是模拟，实际应用中需要真正的视频播放逻辑
    videoElement.classList.add('playing');
    
    // 5秒后重置为初始状态（仅用于原型演示）
    setTimeout(() => {
        if (playIcon) {
            playIcon.style.display = 'block';
        }
        videoElement.classList.remove('playing');
    }, 5000);
} 